package teleradiologia.service;

import java.util.List;

import teleradiologia.domain.Address;
import teleradiologia.domain.Diagnosticlab;
import teleradiologia.domain.Ordertype;
import teleradiologia.repository.AddressDao;
import teleradiologia.repository.DiagnosticlabDao;

public class DiagnosticlabManipulatorImpl implements DiagnosticlabManipulator {

	private DiagnosticlabDao diagnosticlabDao;
	private AddressDao addressDao;

	@Override
	public void setAddressDao(AddressDao dao) {
		this.addressDao = dao;
	}

	@Override
	public void delete(Diagnosticlab diagnosticlab) {
		this.diagnosticlabDao.delete(diagnosticlab);
		this.addressDao.delete(diagnosticlab.getAddress());
	}

	@Override
	public List<Diagnosticlab> getAll() {
		return this.diagnosticlabDao.getAll();
	}

	@Override
	public Diagnosticlab getByKrsnumber(String krsnumber) {
		return this.diagnosticlabDao.getByKrsnumber(krsnumber);
	}

	@Override
	public void setDiagnosticlabDao(DiagnosticlabDao diagnosticlabDao) {
		this.diagnosticlabDao = diagnosticlabDao;
	}

	@Override
	public void update(Diagnosticlab diagnosticlab) {
		this.addressDao.update(diagnosticlab.getAddress());
		this.diagnosticlabDao.update(diagnosticlab);
	}

	@Override
	public void create(Diagnosticlab diagnosticlab, Address address) {
		long id = this.addressDao.create(address);

		diagnosticlab.setAddress(this.addressDao.getById(id));
		this.diagnosticlabDao.create(diagnosticlab);
	}

	@Override
	public List<Object[]> getAllByOrdertype(Ordertype ordertype) {
		return this.diagnosticlabDao.getAllByOrdertype(ordertype);
	}

}
